Remus: Do bitmap scan word-by-word before bit-by-bit.
authorKeir Fraser <keir.fraser@citrix.com>
Mon, 9 Nov 2009 19:17:22 +0000 (19:17 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Mon, 9 Nov 2009 19:17:22 +0000 (19:17 +0000)
For sparse bitmaps and large domains this saves a lot of time.

Signed-off-by: Brendan Cully <brendan@cs.ubc.ca>
tools/libxc/xc_domain_save.c

index 72ffbe6f46210185969efaad002afbdb8ca9d9a2..30c1b6d3a41161dc5b69bde61970cb9b5c7b87c0 100644 (file)
@@ -94,6 +94,8 @@ struct outbuf {
 
 #define BITMAP_SHIFT(_nr) ((_nr) % BITS_PER_LONG)
 
+#define ORDER_LONG (sizeof(unsigned long) == 4 ? 5 : 6)
+
 static inline int test_bit (int nr, volatile void * addr)
 {
     return (BITMAP_ENTRY(nr, addr) >> BITMAP_SHIFT(nr)) & 1;
@@ -1164,6 +1166,14 @@ int xc_domain_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
 
                 if ( completed )
                 {
+                    /* for sparse bitmaps, word-by-word may save time */
+                    if ( !to_send[N >> ORDER_LONG] )
+                    {
+                        /* incremented again in for loop! */
+                        N += BITS_PER_LONG - 1;
+                        continue;
+                    }
+
                     if ( !test_bit(n, to_send) )
                         continue;